package flex.cc.uac.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import flex.cc.base.dto.LoginAuthDto;
import flex.cc.core.support.BaseController;
import flex.cc.system.vo.DictOptionVo;
import flex.cc.uac.entity.UacUserEntity;
import flex.cc.uac.service.UacUserService;
import flex.cc.uac.vo.UserInfoVo;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 用户管理主页面.
 */
@RestController
@RequestMapping(value = "/uac/user")
public class UacUserCommonController extends BaseController {
    @Resource
    private UacUserService uacUserService;

    /**
     * 查询用户列表.
     */
    @PostMapping(value = "/list")
    @ApiOperation(httpMethod = "POST", value = "查询用户列表")
    public Wrapper<List<UacUserEntity>> queryUserListWithPage(@ApiParam(name = "user", value = "用户信息")
                                                        @RequestBody(required = false) UacUserEntity uacUser) {
    	QueryWrapper<UacUserEntity> queryWrapper = new QueryWrapper<>();
    	queryWrapper.eq("status", "ENABLE");
        List<UacUserEntity> list = uacUserService.list(queryWrapper);
        return WrapMapper.ok(list);
    }
    /**
     *  根据用户ID查询用户信息
     */
    @ApiOperation(value = "根据用户ID查询用户信息")
    @PostMapping(value = "/queryUserInfoById/{id}")
    public Wrapper<UserInfoVo> queryUserInfoById(@ApiParam(name = "id", value = "用户ID") @PathVariable Long id){
        UserInfoVo vo =  uacUserService.queryUserInfoById(id);
        return  WrapMapper.ok(vo);
    }

    /**
     * 查询用户下拉列表
     * @param userType：用户类别
     * @param upperVal：归属的上级，级联显示时会用到
     * @param belongFlag：是否考虑用户的归属机构
     * @return
     */
    @GetMapping(value = "/getUserOptions")
    @ApiOperation(httpMethod = "get", value = "查询用户下拉列表")
    public Wrapper<List<DictOptionVo>> getUserOptions(@RequestParam(required = false) String userType, String upperVal, String belongFlag) {
    	LoginAuthDto loginAuthDto = getLoginAuthDto();
    	List<DictOptionVo> userOptions = uacUserService.getSelectOptions(userType, upperVal, belongFlag, loginAuthDto);
        return WrapMapper.ok(userOptions);
    }
   

}
